package com.learning.spring.ioc.bean.xml.injection;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * ClassName: InjectionParameter
 * Description: 依赖注入参数详解
 * Date: 2018/7/26 9:55 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
public class InjectionParameter {

    public static void main(String[] args) {
        test();
        test2();
    }

    /**
     * 字面值：基本类型、String、封装类都可以采用字面值注入
     * 注意 null 值
     */
    static void test() {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-context.xml");

        BeanParameter beanParameter = context.getBean("beanParameter", BeanParameter.class);

        System.out.println(beanParameter);
    }


    static void test2() {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-context.xml");

        BeanParameter beanParameter = context.getBean("beanParameter", BeanParameter.class);

        System.out.println(beanParameter);
    }
}


class BeanParameter {
    private String name;
    private int num;
    private String desc;
    private String home;

    public void setName(String name) {
        this.name = name;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public void setHome(String home) {
        this.home = home;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("BeanParameter{");
        sb.append("name='").append(name).append('\'');
        sb.append(", num=").append(num);
        sb.append(", desc='").append(desc).append('\'');
        sb.append(", home='").append(home).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
